﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <script src="../scripts/jquery-1.10.2.min.js"></script>
    <script>
        var db = openDatabase("myDb", "1.0", "test db", 1024 * 10);
        function Add() {
            db.transaction(function (fx) {
                fx.executeSql("create table if not exists users(username text,pwd text)");
                var username = $("#txtUserName").val();
                var pwd = $("#txtpwd").val();
                fx.executeSql("insert into users values (?,?)", [username, pwd], function () {
                    alert('添加成功');
                })
            })
        }
        function sel() {

            var sql = "select * from users where 1=1";
            var username = $("#txtSUserName").val();
            if (username!="") {
                sql = sql + " and username='" + username + "' ";
            }
           
            db.transaction(function (fx) {
                fx.executeSql(sql, [], function (fx, data) {
                    alert(data.rows.length);
                    $.each(data.rows, function (index,row) {
                        var s = "<div>" + row.username + "</div>";
                        $("#remark").append(s);
                    })
                });
            })
        }
        function del() {

            var sql = "delete from users where 1=1";
            var username = $("#txtSUserName").val();
            if (username != "") {
                sql = sql + " and username='" + username + "' ";
            }

            db.transaction(function (fx) {
                fx.executeSql(sql, [], function (fx, data) {
                    alert(data.rows.length);
                    $.each(data.rows, function (index, row) {
                        var s = "<div>删除" + row.username + "</div>";
                        $("#remark").append(s);
                    })
                });
            })
        }
    </script>
</head>
<body>
    <div><input type="text" id="txtUserName" /><input type="password" id="txtpwd" />
    <input type="button" value="保存" onclick="Add()" /></div>
    <div><input type="text" id="txtSUserName" /><input type="button" value="查询" onclick="sel()" /></div>
    <div><input type="text" id="txtDUserName" /><input type="button" value="删除" onclick="del()" /></div>
    <div id="remark"></div>
</body>
</html>
